//
//  Team9ExpertMoreTopicVC.m
//  Team9Project
//
//  Created by 朱嘉祺 on 15/10/21.
//  Copyright © 2015年 apple. All rights reserved.
//

#import "Team9ExpertMoreTopicVC.h"
#import "Team9ExpertDiscussModel.h"
#import "Team9ExpertDiscussCell.h"
#import "Team9JQHeader.h"

@interface Team9ExpertMoreTopicVC ()<UITableViewDataSource, UITableViewDelegate>
@property(nonatomic, strong) NSArray *array;
@property(nonatomic, strong) UITableView *tableView;
@end

@implementation Team9ExpertMoreTopicVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 64, 0);
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:_tableView];
    self.tableView.tableFooterView = [UIView new];
    self.tableView.rowHeight = 150 * WIDTH/ 375;
    
    self.empty = [Team9EmptyTool toolWithScrollView:self.tableView];
    
    [self createData];
}
#pragma mark tableView methods for protols
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    //#warning test!
    return self.array.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *reuse = @"discussReuse";
    Team9ExpertDiscussCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (!cell) {
        cell = [[Team9ExpertDiscussCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse];
    }
    cell.model = self.array[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    Team9ExpertDiscussModel *model = self.array[indexPath.row];
    Team9s_discussViewController *vc = [Team9s_discussViewController new];
    vc.topicID = model.modelId;
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
}
- (void)setArray:(NSArray *)array
{
    if (_array != array) {
        _array = array;
        [self.tableView reloadData];
    }
}
#pragma mark 申请数据
- (void)createData{
    self.tool = [Team9RefreshTool toolWithScrollView:self.tableView url:self.url style:^NSArray *(id result) {
        return [Team9ExpertDiscussModel baseModelByArr:result[@"data"][@"user_topic_list"][@"topic_list"]];
    } refresh:^(NSArray *array) {
        self.array = array;
    } empty:self.empty];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
